/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package DAO;

import Entidad.Estiramiento;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;

/**
 *
 * @author Carlos
 */
public class EstiramientoDAO {


    public boolean save(Estiramiento estiramiento){
        boolean flag = true;
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("JPALa1-ModelPU");
        EntityManager em = emf.createEntityManager();
        EntityTransaction trans =em.getTransaction();
        try{
            trans.begin();
            em.persist(estiramiento);
            trans.commit();
        }
        catch(Exception e){
            flag=false;
        }
        return flag;
    }
    public Estiramiento getEstiramientoById(Integer id){
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("JPALa1-ModelPU");
        EntityManager em = emf.createEntityManager();
        return em.find(Estiramiento.class, id);
    }
    public boolean update(Estiramiento estiramiento){
        boolean flag =true;
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("JPALa1-ModelPU");
        EntityManager em = emf.createEntityManager();
        EntityTransaction trans =em.getTransaction();
        try{
            trans.begin();
            em.merge(estiramiento);
            trans.commit();
        }
        catch(Exception e){
            flag =false;
        }
        return flag;
    }
    public boolean delete(Estiramiento estiramiento){
        boolean flag = true;
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("JPALa1-ModelPU");
        EntityManager em =emf.createEntityManager();
        EntityTransaction trans=em.getTransaction();
        try{
            trans.begin();
            em.remove(em.merge(estiramiento));
            trans.commit();
        }
        catch(Exception e){
            flag=false;
        }
        return flag;
    }

  }
